Ext.define("org.jks.AddDeviceRe", {
			extend : "Ext.window.Window",
			style:'border:1px solid #5bb6b1',
			border:false,
			closable : true,
			modal: true,
			width : 500,
			height : 400,
			closable : true,
			title : "履历表",
			deviceReGrid : null, ///对应的Grid表格
			rowIndex : -1,
			deviceReId : -1,   //对应DeviceRe的id
			callback: undefined,
			successFunc: undefined,
			floating : true,
			initComponent : function() {
				var me = this;
				var required = '<span style="color:red;font-weight:bold" data-qtip="Required">*</span>';
				me.form = Ext.create("Ext.form.Panel",{
					border : false,
					margin: '5 5',
					padding : '5',
					items : [{
						id : 'FlightTime',
						xtype : 'datefield',
						format : "Y-m-d",
						fieldLabel : '飞行日期',
						allowBlank : false,
						afterLabelTextTpl: required
					},{
						id : 'Type',
						xtype : 'textfield',
						fieldLabel : '飞行类型',
						allowBlank : false,
						afterLabelTextTpl: required
					},Ext.create('Ext.form.field.Number', {
						id : 'Count',
						fieldLabel : '架次',
				        minValue: 1,
				        allowBlank : false,
						afterLabelTextTpl: required
					}),Ext.create('Ext.form.field.Number', {
						id : 'Mileage',
						fieldLabel : '里程(Km)',
				        minValue: 1,
				        allowBlank : false,
						afterLabelTextTpl: required
					}),Ext.create('Ext.form.field.Number', {
						id : 'Duration',
						fieldLabel : '时长(min)',
				        minValue: 1,
				        allowBlank : false,
						afterLabelTextTpl: required
					}),{
						id : 'Info',
						xtype : 'textarea',
						fieldLabel : '起降点信息',
						width : 440
					},{
						id : 'ExceptionInfo',
						xtype : 'textarea',
						fieldLabel : '系统异常信息',
						width : 440
					}]
				});
				
				
				me.items = [me.form];
				me.okButton = Ext.create('Ext.button.Button', {
					text : '确定',
					handler : function() 
					{
						var time = Ext.getCmp("FlightTime").getValue();
						
						if(me.rowIndex == -1)
						{
							if (!me.form.isValid()) {
								return;
							}
							
							me.deviceReGrid.store.add({
								'Id' : 0,
								'FlightTime' : time, 
								'Type' : Ext.getCmp('Type').getValue(), 
								'Count' : Ext.getCmp('Count').getValue(),
								'Mileage' : Ext.getCmp('Mileage').getValue(), 
								'Duration' : Ext.getCmp('Duration').getValue(), 
								'Info' : Ext.getCmp('Info').getValue(), 
								'ExceptionInfo' : Ext.getCmp('ExceptionInfo').getValue()
							});
						}
						else 
						{
							me.deviceReGrid.store.getAt(me.rowIndex).set('FlightTime', time);
							me.deviceReGrid.store.getAt(me.rowIndex).set('Type' , Ext.getCmp('Type').getValue());
							me.deviceReGrid.store.getAt(me.rowIndex).set('Count' , Ext.getCmp('Count').getValue());
							me.deviceReGrid.store.getAt(me.rowIndex).set('Mileage' , Ext.getCmp('Mileage').getValue());
							me.deviceReGrid.store.getAt(me.rowIndex).set('Duration' , Ext.getCmp('Duration').getValue());
							me.deviceReGrid.store.getAt(me.rowIndex).set('Info' , Ext.getCmp('Info').getValue());
							me.deviceReGrid.store.getAt(me.rowIndex).set('ExceptionInfo' , Ext.getCmp('ExceptionInfo').getValue());
							
						}		
						me.close();
					}
				});
				me.cancelButton = Ext.create('Ext.button.Button', {
							text : '取消',
							handler : function() {
								me.close();
							}
						});
				me.buttons = [me.okButton, me.cancelButton];
				me.callParent();
			},
			listeners:{
				show: function(self, eOpts){
					Ext.getCmp('FlightTime').focus();
				},
				afterrender : function()
				{
					var me = this;
					if(me.rowIndex != -1)
					{
						var data = me.deviceReGrid.store.getAt(me.rowIndex);
						Ext.getCmp('FlightTime').setValue(data.get('FlightTime'));
						Ext.getCmp('Type').setValue(data.get('Type'));
						Ext.getCmp('Count').setValue(data.get('Count'));
						Ext.getCmp('Mileage').setValue(data.get('Mileage'));
						Ext.getCmp('Duration').setValue(data.get('Duration'));
						Ext.getCmp('Info').setValue(data.get('Info'));
						Ext.getCmp('ExceptionInfo').setValue(data.get('ExceptionInfo'));
					}
				}
			}
		});